﻿using System.Windows;
using System.Windows.Input;
using IMClient.ViewModels;

namespace IMClient.View;

public partial class LoginWindow : Window
{
    public LoginWindow()
    {
        InitializeComponent();

        DataContext=new LoginViewModel();

        // 由于 PasswordBox 的特殊性，需要手动处理密码绑定
        LoginPasswordBox.PasswordChanged += (s, e) =>
        {
            if (DataContext is LoginViewModel vm)
            {
                vm.Password = LoginPasswordBox.Password;
            }
        };
    }

    private void RegisterButton_Click(object sender, RoutedEventArgs e)
    {
        RegisterWindow registerWindow = new RegisterWindow();
        registerWindow.Show();
        Close();
    }

    private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ButtonState == MouseButtonState.Pressed)
        {
            DragMove(); // 拖动窗口
        }
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Close();
    }
}